/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.platformservice.persistence.api.messagebean;

import org.proteusframework.core.api.model.IDescriptor;
import org.proteusframework.core.api.model.IMetadata;
import org.proteusframework.core.api.model.INamespace;
import org.proteusframework.platformservice.persistence.messagebean.DataType;

/**
 * Agnostic description of a singular field defined as part of an {@link IMessageBeanDescriptor}. Instances of
 * <code>IMessageField</code> must be constructed using the {@link org.proteusframework.platformservice.persistence.messagebean.MessageBeanBuilder}.
 * <p/>
 * Specific data types supported are documented by specific concrete persistence service implementations.
 *
 * @author Tacoma Four
 */
public interface IMessageBeanProperty extends INamespace, IDescriptor, IMetadata
{
    /**
     * Data type of the field.
     *
     * @return Data type
     */
    DataType getDataType();

    /**
     * Contextual length of the field, as applicable. For example, a StringType may define its upper-bound length as
     * 255, while describing the length of an integer is not necessary.
     * <p/>
     * All array data types may define an explicit length. When no length is specified (length == 0), it indicates that
     * the array should be unbounded. Each persistence service implementation must document if it supports unbounded
     * arrays or not.
     *
     * @return Field length
     */
    int getLength();

    /**
     * Contextual precision of the field, as applicable. This field is only used for {@link DataType#DoubleType},
     * {@link DataType#FloatType}, etc.
     *
     * @return Field precision
     */
    int getPrecision();

    /**
     * Defines if the field supports null values
     *
     * @return true, if the getter can legally return a null value
     */
    boolean isNullable();

    /**
     * Defines if the field is the Object ID (OID) that uniquely identifies the object.
     *
     * @return true, if the getter is an ID
     */
    boolean isPrimaryKeyMember();
}
